www.gusucode.com > VC++ Windows错误信息查看器源代码-源码程序 > VC++ Windows错误信息查看器源代码-源码程序/code/WinErrCodeViewerDlg.cpp

    // WinErrCodeViewerDlg.cpp : implementation file
// Download by http://www.NewXing.com
#include "stdafx.h"
#include "WinErrCodeViewer.h"
#include "ListDialog.h"
#include "WinErrCodeViewerDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	CString	m_strAboutMessage;
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	RECT m_RectLink;
	//{{AFX_MSG(CAboutDlg)
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	virtual BOOL OnInitDialog();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	m_strAboutMessage = _T("   该软件能够查询Windows系统错误代码的信息,你可以清楚的知道什么错误代码是代表什么错误信息,而且它还是一个免费软件,你可以自由的拷贝和使用!欢迎大家使用这个软件,请大家多多批评指教!                                                与我联系:daixi1703163@163.com");
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	DDX_Text(pDX, IDC_ABOUTMESSAGE, m_strAboutMessage);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
	ON_WM_MOUSEMOVE()
	ON_WM_LBUTTONDOWN()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWinErrCodeViewerDlg dialog

CWinErrCodeViewerDlg::CWinErrCodeViewerDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CWinErrCodeViewerDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CWinErrCodeViewerDlg)
	m_nErrorCode = 0;
	m_strErrorMessage = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CWinErrCodeViewerDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CWinErrCodeViewerDlg)
	DDX_Text(pDX, IDC_ERRORCODE, m_nErrorCode);
	DDV_MinMaxInt(pDX, m_nErrorCode, 0, 12000);
	DDX_Text(pDX, IDC_ERRORMESSAGE, m_strErrorMessage);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CWinErrCodeViewerDlg, CDialog)
	//{{AFX_MSG_MAP(CWinErrCodeViewerDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_EN_CHANGE(IDC_ERRORCODE, OnChangeErrorcode)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDCOK, OnCok)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWinErrCodeViewerDlg message handlers

BOOL CWinErrCodeViewerDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here

	if(m_nErrorCode==0)
	{
		m_strErrorMessage="操作成功完成。";
		UpdateData(FALSE);
	}
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CWinErrCodeViewerDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CWinErrCodeViewerDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CWinErrCodeViewerDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CWinErrCodeViewerDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here

	CAboutDlg aboutdlg;
	aboutdlg.DoModal();
	
}

void CWinErrCodeViewerDlg::OnChangeErrorcode() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here

	int nErrorCode;
	CString strErrorMessage;
	LPVOID lpMsgBuf;
	lpMsgBuf=LocalLock(LocalAlloc(LMEM_MOVEABLE|LMEM_ZEROINIT,1000));
	if(lpMsgBuf==NULL)
	{
		MessageBox("内存分配失败!","错误");
		exit(1);
	}

	UpdateData();
    nErrorCode=m_nErrorCode;
	SetLastError(nErrorCode);
	FormatMessage( 
		FORMAT_MESSAGE_ALLOCATE_BUFFER| 
		FORMAT_MESSAGE_FROM_SYSTEM| 
		FORMAT_MESSAGE_IGNORE_INSERTS,
		NULL,
		GetLastError(),
		MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), // Default language
		(LPTSTR) &lpMsgBuf,
		0,
		NULL);
	strErrorMessage=(LPCTSTR)lpMsgBuf;
	if(strErrorMessage=="")
	{
		m_strErrorMessage="Undefined error code.          An error message can not be found for this error code.";
	}
	else
	{
		m_strErrorMessage=strErrorMessage;
	}
	LocalFree(lpMsgBuf);
	UpdateData(FALSE);	
}

void CAboutDlg::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default

	if (point.x>m_RectLink.left&&point.x<m_RectLink.right&&point.y>m_RectLink.top&&point.y<m_RectLink.bottom)
	{
		HCURSOR hCursor;
		hCursor=AfxGetApp()->LoadCursor(IDC_HAND);
		SetCursor(hCursor);
	}
	
	
	CDialog::OnMouseMove(nFlags, point);
}

void CAboutDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default

	if (point.x>m_RectLink.left&&point.x<m_RectLink.right&&point.y>m_RectLink.top&&point.y<m_RectLink.bottom)
	{ 
       if (nFlags==MK_LBUTTON) 

         {  
            ShellExecute(0, NULL, "http://www.pcvc.net", NULL,NULL, SW_NORMAL);
          }
     }
	
	CDialog::OnLButtonDown(nFlags, point);
}

BOOL CAboutDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here

	GetDlgItem(IDC_LINK)->GetWindowRect(&m_RectLink);
	ScreenToClient(&m_RectLink);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CWinErrCodeViewerDlg::OnButton2() 
{
	// TODO: Add your control notification handler code here

	CListDialog ListDialog;
	ListDialog.DoModal();
	
}

void CWinErrCodeViewerDlg::OnOK() 
{
	// TODO: Add extra validation here
	
	//CDialog::OnOK();
}

void CWinErrCodeViewerDlg::OnCok() 
{
	// TODO: Add your control notification handler code here

	CDialog::OnOK();
	
}